package com.stiff.manage.controller;

import com.stiff.manage.pojo.ItemParam;
import com.stiff.manage.pojo.ItemParamItem;
import com.stiff.manage.service.ItemParamItemService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("item/param/item")
public class ItemParamItemController {
    private static final Logger LOGGER = LoggerFactory.getLogger(ItemParamItemController.class);
    @Autowired
    private ItemParamItemService itemParamItemService;

    /**
     * 根据商品ID查询商品规格
     * @param itemCatId
     * @return
     */
    @RequestMapping(value = "{itemCatId}",method = RequestMethod.GET)
    public ResponseEntity<ItemParamItem> queryByItemId(@PathVariable("itemCatId")Long itemCatId){
        try {
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("【根据商品ID查询商品规格】itemCatId={}",itemCatId);
            }
            ItemParamItem record = new ItemParamItem();
            record.setItemId(itemCatId);
            ItemParamItem itemParamItem = this.itemParamItemService.queryOne(record);
            if(null==itemParamItem){
                return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
            }
            return ResponseEntity.ok(itemParamItem);
        } catch (Exception e) {
            LOGGER.error("【根据商品ID查询商品规格失败！】itemCatId="+itemCatId,e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
}
